package domain.entities;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;

import java.util.ArrayList;
import java.util.List;

import static javax.persistence.GenerationType.IDENTITY;

@Entity
@Table(name = "droga_importacion", catalog = "bms")
public class DrogaImportacion implements java.io.Serializable {

    private Integer id;
    private Integer initialQty;
    private Integer currentBalance;
    private String unit;
    private Importacion importacion;
    private Droga droga;
    private List<ProtocoloImportacion> protocoloImportaciones = new ArrayList<ProtocoloImportacion>();

    // Constructors

    /** default constructor */
    public DrogaImportacion() {

    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "current_balance")
    public Integer getCurrentBalance() {
        return currentBalance;
    }

    public void setCurrentBalance(Integer currentBalance) {
        this.currentBalance = currentBalance;
    }

    @Column(name = "initialQty")
         public Integer getInitialQty() {
        return initialQty;
    }

    public void setInitialQty(Integer initialQty) {
        this.initialQty = initialQty;
    }

    @Column(name = "unit")
    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    @ManyToOne()
    public Importacion getImportacion() {
        return this.importacion;
    }

    public void setImportacion(Importacion importacion) {
        this.importacion = importacion;
    }

    @ManyToOne()
    public Droga getDroga() {
        return this.droga;
    }

    public void setDroga(Droga droga) {
        this.droga = droga;
    }

    @Override
    public boolean equals(Object obj) {
        DrogaImportacion otro = (DrogaImportacion)obj;
        return this.id.equals(otro.id);
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "drogaImportacion")
    @LazyCollection(LazyCollectionOption.FALSE)
    public List<ProtocoloImportacion> getProtocoloImportaciones() {
        return this.protocoloImportaciones;
    }

    public void setProtocoloImportaciones(List<ProtocoloImportacion> protocoloImportaciones) {
        this.protocoloImportaciones = protocoloImportaciones;
    }

    public void addProtocoloImportacion(ProtocoloImportacion pi) {
        this.protocoloImportaciones.add(pi);
    }
}
